<template lang='pug'>
  .page
    .pl-20.pr-20.bg-white
      Table.hasTitle-table.beautiful-table(width="100%" stripe :loading="loading" :columns="thead" :data="listData")
        div(slot="header")
          .pull-left.table-title-lefttxt
            span.leftText
              | 签约企业总数:
              span.text-info.pl-5.pr-5.font-weight {{totalcount}}
              | 家
        .clearfix.pl-20.pr-20(slot="footer")
          Page(:total="totalcount" :current="pageIndex" :page-size="pageSize" prev-text="上一页" next-text="下一页" @on-change="pageChange" show-total)

</template>

<script>
import fxzpApi from '@/api/fx-zp.api.js'

export default {
  name: 'enterprise',
  data () {
    return {
      // 搜索关键字
      searchValue: '',
      // 翻页索引
      pageIndex: 1,
      // 每页的数目
      pageSize: 10,
      // 总条目
      totalcount: 0,
      listData: [],
      loading: false,
      thead: [
        {
          title: '企业名称',
          align: 'center',
          minWidth: 200,
          tooltip: true,
          key: 'enterprise_name',
          render: (h, params) => {
            let row = params.row
            return h('span', {
              'class': 'hover-table',
              style: {
                color: '#188cc7',
                cursor: 'pointer'
              },
              on: {
                click: () => {
                  // this.$router.push({ name: 'sign-contract', params: { id: row.id, eid: row.enterprise_id}})
                } 
              }
            }, params.row.enterprise_name)
          }
        },
        {
          title: '组织机构代码',
          align: 'center',
          minWidth: 150,
          tooltip: true,
          key: 'social_credit_code'
        },
        {
          title: '签约时间',
          align: 'center',
          minWidth: 225,
          tooltip: true,
          render: (h, params) => {
            let row = params.row
            let date = ''
            if (row.sign_data) {
              date = row.sign_data.slice(0, 10).replace(/T/g,' ')
            }
            return h('span', date)
          }
        },
        {
          title: '结算时间',
          align: 'center',
          minWidth: 225,
          tooltip: true,
          render: (h, params) => {
            let row = params.row
            let date = ''
            if (row.settlement_data) {
              date = row.settlement_data.slice(0, 10).replace(/T/g,' ')
            }
            return h('span', date)
          }
        },
        {
          title: '平台费率',
          align: 'center',
          minWidth: 100,
          tooltip: true,
          key: 'royalty_rate'
        },
        {
          title: '保证金',
          align: 'center',
          minWidth: 100,
          tooltip: true,
          key: 'prepaid_bonus'
        },
        {
          title: '签约状态',
          align: 'center',
          minWidth: 100,
          render: (h, params) => {
            let row = params.row
            let str = ''
            let arr = this.getStatusFn('Contract_Type')
            let text = arr.filter((item) => {
              return item.id === row.contract_status
            })
            if (text && text.length > 0) {
              str = text[0].e_name
            } else {
              str = '未填写'
            }
            return h('span', str)
          }
        }
      ]
    }
  },
  mounted () {
    // this.whetherType = commonJs.getStatusFn('WhetherType')
    this.getListData()
  },
  methods: {
    // 获取企业列表
    getListData () {
      this.loading = true
      fxzpApi.GetEnterPriseContracts({
        txtSearch: '',
        PageSize  : this.pageSize,
        PageIndex : this.pageIndex
      }).then(res => {
        this.loading = false
        if (res.data.success) {
          this.listData = res.data.data
          this.totalcount = res.data.totalRows
        } else {
          this.$Message.error({
            content: res.data.message,
            duration: 10,
            closable: true
          })
        }
      })
    },
    // 翻页
    pageChange (index) {
      this.pageIndex = index
      this.getListData()
    },
    getStatusFn (encode) {
      let allStatus = JSON.parse(localStorage.getItem('FXZP_STATUS'))
      // console.log(allStatus)
      let statusArr = allStatus.filter((item) => {
        return item.e_encode === encode
      })
      return statusArr 
    }
  }
  
}
</script>

<style lang="less">
</style>
